//
//  HMSportMaskPreView.m
//  BlackHorseLine
//
//  Created by made on 17/3/13.
//  Copyright © 2017年 made. All rights reserved.
//

#import "HMSportMaskPreView.h"
#import "UIColor+HMColorAddition.h"

@interface HMSportMaskPreView()

@property(nonatomic, weak)IBOutlet UIImageView *imageView;

@end

@implementation HMSportMaskPreView

//4
- (void)awakeFromNib
{
    [super awakeFromNib];
    //使用清除颜色,必须要设置当前的背景颜色为透明(此处应该注意线程延迟问题,先设置背景颜色为透明,再填充颜色)
    self.backgroundColor = [UIColor clearColor];
    
}



//8.视图将要展现时,我们拥有最后一次机会可以对视图进行重绘
- (void)drawRect:(CGRect)rect {
    // Drawing code
    //使用清除图层清除颜色之后,1,我们想要显示背景颜色,只能使用贝塞尔路径填充颜色 //2.必须要设置当前的背景颜色为透明(此处应该注意线程延迟问题,先设置背景颜色为透明,再填充颜色)

    //往当前上下文中填充颜色
    //1区域填颜色
    //1.1先填充颜色
    [UIColor colorWithHex:0x24282e];
    //1.2使用贝塞尔路径绘制颜色,自身属性:bounds
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
    //1.3将贝塞尔路径填充到上下文
    [path fill];
    
    //2绘制中间的直线
    //区分左右
    UIBezierPath *linePath = [UIBezierPath bezierPath];
    
    if (self.imageView.frame.origin.x > 0)
    {
        //左侧
        //移动画线
        [linePath moveToPoint:CGPointMake(rect.size.width, 0)];
        //开始画线
        [linePath addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];
    }
    else
    {
        //右侧
        [linePath moveToPoint:CGPointMake(0, 0)];
        [linePath addLineToPoint:CGPointMake(0, rect.size.height)];
    }
    //填充颜色
    [[UIColor colorWithHex:0x1a1a1a] setStroke];
    
    [linePath stroke];
    
    //4.使用绘图上下文清除图层背景颜色,清除图片区域所在的背景颜色,避免遮盖图片
    /**
     第一个参数:绘图上下文
     第二个参数:想要清除颜色的区域
     */
    //为了避免清除颜色边缘产生锯齿,可以清除的时候往内多清除一个像素点
    CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectInset(self.imageView.frame, 1, 1));
}

/*
 //3
 - (void)didMoveToSuperview
 {
 [super didMoveToSuperview];
 }
 
 //2
 - (void)willMoveToSuperview:(UIView *)newSuperview
 {
 [super willMoveToSuperview:newSuperview];
 }
 //5
 - (void)willMoveToWindow:(UIWindow *)newWindow
 {
 [super willMoveToWindow:newWindow];
 }
 
 //6
 - (void)didMoveToWindow
 {
 [super didMoveToWindow];
 }
 
 
 //7
 - (void)layoutSubviews
 {
 
 }
 
 //9
 - (void)willRemoveSubview:(UIView *)subview
 {
 [super willRemoveSubview:subview];
 }
*/


@end
